package adminSys

import (
	db "fiberAmisAdmin/config"
	"time"
)

type AdminSysMenu struct {
	MenuServer *MenuServer
}
type MenuServer struct {
}

func (as *MenuServer) ListToRows(result []map[string]interface{}) []map[string]interface{} {
	for i, record := range result {
		for field, value := range record {
			if field == "updated_at" {
				if timestamp, ok := value.(time.Time); ok {
					record["updated_at"] = timestamp.Format("2006-01-02 15:04:05")
				}
			}
		}

		// 查询子菜单
		children := []map[string]interface{}{}
		db.MySQLDB.Table("admin_menus").Where("parent_id = ?", record["id"]).Find(&children)
		record["children"] = children

		result[i] = record
	}
	return result
}
